/**
 * 
 */
package org.jenkon.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Util class for system helping methods.
 * 
 * @author Jens Konopka
 * 
 */
public final class SystemUtils {

	/**
	 * Hide public constructor for this util class.
	 */
	private SystemUtils() {
	}

	/**
	 * Get the name of the currently system. For example 'Windows 7' or 'Linux'.
	 * 
	 * @return the name of the system
	 */
	public static String getSystemName() {
		return System.getProperty("os.name");
	}

	/**
	 * Get the version of the currently system.
	 * 
	 * @return the version of the current system.
	 */
	public static String getSystemVersion() {
		return System.getProperty("os.version");
	}

	/**
	 * Get the arch of the currently system.
	 * 
	 * @return the architectur of the current system.
	 */
	public static String getSystemArch() {
		return System.getProperty("os.arch");
	}

	/**
	 * Installation directory for Java Runtime Environment (JRE).
	 * 
	 * @return Installation directory for Java Runtime Environment (JRE).
	 */
	public static String getJavaHome() {
		return System.getProperty("java.home");
	}

	/**
	 * JRE version number.
	 * 
	 * @return JRE version number.
	 */
	public static String getJavaVersion() {
		return System.getProperty("java.version");
	}

	/**
	 * JRE vendor name.
	 * 
	 * @return JRE vendor name.
	 */
	public static String getJavaVendor() {
		return System.getProperty("java.vendor");
	}

	/**
	 * JRE vendor url.
	 * 
	 * @return JRE vendor url.
	 */
	public static String getJavaVendorUrl() {
		return System.getProperty("java.vendor.url");
	}

	/**
	 * Path used to find directories and JAR archives containing class files. Elements of the class
	 * path are separated by a platform-specific character specified in the path.separator property.
	 * 
	 * @return the path
	 */
	public static String getJavaClassPath() {
		return System.getProperty("java.class.path");
	}

	/**
	 * Paths used to find directories and JAR archives containing class files.
	 * 
	 * @return {@link List} with pathes
	 */
	public static List<String> getJavaClassPaths() {
		final List<String> list = new ArrayList<String>();
		for (final String value : getJavaClassPath().split(getPathSeparator())) {
			list.add(value);
		}
		return list;
	}

	/**
	 * Get all pathes from java class path.
	 * 
	 * @see #getJavaClassPaths()
	 * @return {@link List} with {@link File} objects from java class path
	 */
	public static List<File> getJavaClassPathFiles() {
		final List<File> list = new ArrayList<File>();
		for (final String value : getJavaClassPaths()) {
			list.add(new File(value));
		}
		return list;
	}

	/**
	 * Character that separates components of a file path. This is "/" on UNIX and "\" on Windows.
	 * 
	 * @return the separates component
	 */
	public static String getFileSeparator() {
		return System.getProperty("file.separator");
	}

	/**
	 * Sequence used by operating system to separate lines in text files.
	 * 
	 * @return the separates component
	 */
	public static String getLineSeparator() {
		return System.getProperty("line.separator");
	}

	/**
	 * Path separator character used in java.class.path.
	 * 
	 * @return the separates component
	 */
	public static String getPathSeparator() {
		return System.getProperty("path.separator");
	}

	/**
	 * User working directory.
	 * 
	 * @return the directory as string
	 */
	public static String getUserDir() {
		return System.getProperty("user.dir");
	}

	/**
	 * User home directory.
	 * 
	 * @return the directory as string
	 */
	public static String getUserHome() {
		return System.getProperty("user.home");
	}

	/**
	 * User account name.
	 * 
	 * @return the name as string
	 */
	public static String getUserName() {
		return System.getProperty("user.name");
	}

}
